home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / PageMaker 6.5 SDK Mac / SourceCode / PageMakerClassLibrary / LowLevel / PQuery.cpp < prev    next >
C/C++ Source or Header  |  1996-09-05  |  7KB  |  252 lines

  1. /*
  2.  *--- PQuery.cpp ----------------------------------------------------------
  3.  * Copyright (c) 1995-96 Adobe Systems Incorporated.  All rights reserved.
  4.  * Created on Thu, Oct 12, 1995 @ 9:47 PM by Paul Ferguson.
  5.  *
  6.  * Description:  For notes about this class, refer to the
  7.  * header file PQuery.h
  8.  *-------------------------------------------------------------------------
  9.  */
  10.  
  11.  
  12. #include "PQuery.h"
  13. #include "PRequestBuf.h"
  14. #include "CIBasic.h"
  15. #include "CIInterfaceManager.h"
  16. #include "PMInterfaceIDs.h"
  17.  
  18. extern PMMessage * gPMMessage;
  19.  
  20. #include "PMCQErrs.h"
  21.  
  22. /*
  23.  *--- PQuery constructor ---------------------------------------
  24.  * Issue a PageMaker query that returns a single short value.
  25.  *--------------------------------------------------------------
  26.  */
  27.  
  28. PQuery::PQuery(ePMQuery op, short &aShort)
  29. {
  30.     ClearRequestBlock();
  31.  
  32.     itsPB->replyData  = &aShort;
  33.     itsPB->replySize  = sizeof(short);
  34.     itsPB->replyStyle = kXRSPointer;
  35.     itsPB->replyUnits = 0;
  36.  
  37.     DoQuery(op);
  38. }
  39.  
  40.  
  41. /*
  42.  *--- PQuery constructor ---------------------------------------
  43.  * Issue a PageMaker query that returns a single long value.
  44.  *--------------------------------------------------------------
  45.  */
  46.  
  47. PQuery::PQuery(ePMQuery op, long &aLong)
  48. {
  49.     ClearRequestBlock();
  50.  
  51.     itsPB->replyData  = &aLong;
  52.     itsPB->replySize  = sizeof(long);
  53.     itsPB->replyStyle = kXRSPointer;
  54.     itsPB->replyUnits = 0;
  55.         
  56.     DoQuery(op);
  57. }
  58.  
  59. /*
  60.  *--- PQuery constructor ---------------------------------------
  61.  * Issue a PageMaker query that returns a handle allocated
  62.  * by PageMaker.
  63.  *--------------------------------------------------------------
  64.  */
  65.  
  66. PQuery::PQuery(ePMQuery op, PMHandle &aHandle) throw (PMErr)
  67. {
  68.     itsPB->replyData  = NULL;
  69.     itsPB->replySize  = 0L;
  70.     itsPB->replyStyle = kXRSHandle;
  71.         
  72.     ClearRequestBlock();
  73.     DoQuery(op);
  74.     
  75.     aHandle = (PMHandle) itsPB->replyData;
  76.     if (aHandle == NULL)            // a null return handle is definitely a problem...
  77.         throw CQ_FAILURE;
  78. }
  79.  
  80.  
  81. /*
  82.  *--- PQuery constructor ---------------------------------------
  83.  * This constructor is for more efficient access when the 
  84.  * size of the returned query is known ahead of time.
  85.  *--------------------------------------------------------------
  86.  */
  87.  
  88. PQuery::PQuery(ePMQuery op, void * theBuf, size_t len)
  89. {
  90.     ClearRequestBlock();
  91.  
  92.     itsPB->replyData  = theBuf;
  93.     itsPB->replySize  = len;
  94.     itsPB->replyStyle = kXRSPointer;
  95.     itsPB->replyUnits = 0;
  96.         
  97.     DoQuery(op);
  98. }
  99.  
  100. /*
  101.  *--- PQuery constructor ---------------------------------------
  102.  * Execute a query with a PRequestBuf object.
  103.  *
  104.  * Note that this always allocates a heap memory block to return
  105.  * the query result.  You could overload DoQuery with functions
  106.  * optimized for queries with request buffers and returning
  107.  * a fixed length amount of information.
  108.  *--------------------------------------------------------------
  109.  */
  110. PQuery::PQuery(ePMQuery op, PRequestBuf& request, short & aShort)
  111. {
  112.     SetRequestBlock(request);
  113.     
  114.     itsPB->replyData = &aShort;
  115.     itsPB->replySize = sizeof(short);
  116.     itsPB->replyStyle = kXRSPointer;
  117.     itsPB->replyUnits = 0;
  118.  
  119.     DoQuery(op);
  120. }
  121.  
  122.  
  123. /*
  124.  *--- PQuery constructor ---------------------------------------
  125.  * Execute a query with a PRequestBuf object.
  126.  *
  127.  * Note that this always allocates a heap memory block to return
  128.  * the query result.  You could overload DoQuery with functions
  129.  * optimized for queries with request buffers and returning
  130.  * a fixed length amount of information.
  131.  *--------------------------------------------------------------
  132.  */
  133. PQuery::PQuery(ePMQuery op, PRequestBuf& request, long & aLong)
  134. {
  135.     SetRequestBlock(request);
  136.     
  137.     itsPB->replyData = &aLong;
  138.     itsPB->replySize = sizeof(long);
  139.     itsPB->replyStyle = kXRSPointer;
  140.     itsPB->replyUnits = 0;
  141.  
  142.     DoQuery(op);
  143. }
  144.  
  145.  
  146. /*
  147.  *--- PQuery constructor ---------------------------------------
  148.  * Execute a query with a PRequestBuf object.
  149.  *
  150.  * Note that this always allocates a heap memory block to return
  151.  * the query result.  You could overload DoQuery with functions
  152.  * optimized for queries with request buffers and returning
  153.  * a fixed length amount of information.
  154.  *--------------------------------------------------------------
  155.  */
  156. PQuery::PQuery(ePMQuery op, PRequestBuf& request, PMHandle & aHandle)
  157. {
  158.     SetRequestBlock(request);
  159.  
  160.     itsPB->replyData = NULL;
  161.     itsPB->replySize = 0;
  162.     itsPB->replyStyle = kXRSHandle;
  163.     itsPB->replyUnits = 0;
  164.  
  165.     DoQuery(op);
  166.  
  167.     aHandle = (PMHandle) itsPB->replyData;
  168.     if (aHandle == NULL)            // a null return handle is definitely a problem...
  169.         throw CQ_FAILURE;
  170. }
  171.  
  172.  
  173. /*
  174.  *--- PQuery constructor ---------------------------------------
  175.  * This constructor is for more efficient access when the size 
  176.  * of the returned query is known ahead of time.
  177.  *--------------------------------------------------------------
  178.  */
  179.  
  180. PQuery::PQuery(ePMQuery op, PRequestBuf& request, void * theBuf, size_t len)
  181. {
  182.     SetRequestBlock(request);
  183.     
  184.     itsPB->replyData  = theBuf;
  185.     itsPB->replySize  = len;
  186.     itsPB->replyStyle = kXRSPointer;
  187.     itsPB->replyUnits = 0;
  188.         
  189.     DoQuery(op);
  190. }
  191.  
  192.  
  193. /*
  194.  *--- DoQuery --------------------------------------------------
  195.  * Set opcode and issue callback.  Issue private call into 
  196.  * PCallback superclass.
  197.  *--------------------------------------------------------------
  198.  */
  199.  
  200. void PQuery::DoQuery(ePMQuery op) throw (PMErr)
  201. {
  202.     itsPB->opCode = op;
  203.     try
  204.     {
  205.         CallPageMaker();
  206.     }
  207.     catch (PMErr err)        // If a handle was allocated by PageMaker, should free it.
  208.     {
  209.         if ( (itsPB->replyStyle == kXRSHandle) && (itsPB->replyData != NULL) )
  210.         {
  211.             CIBasic * basicInterface;
  212.             gPMMessage->pInterfaceMgr->AcquirePMInterface((unsigned long)PMIID_BASIC, (void **) &basicInterface);
  213.             basicInterface->PMMemFree(itsPB->replyData);
  214.             itsPB->replyData = NULL;
  215.             gPMMessage->pInterfaceMgr->ReleasePMInterface(basicInterface);
  216.         }
  217.         throw;        // rethrow exception
  218.     }
  219. }
  220.  
  221.  
  222. /*
  223.  *--- SetRequestBlock ------------------------------------------
  224.  * Does what it says...
  225.  *--------------------------------------------------------------
  226.  */
  227.  
  228. void PQuery::SetRequestBlock(PRequestBuf& request)
  229. {
  230.     itsPB->requestData  = (const char *) request;
  231.     itsPB->requestSize  = request.Size();
  232.     itsPB->requestStyle = kXRSPointer;
  233.     itsPB->requestUnits = 0;
  234. }    
  235.  
  236.  
  237. /*
  238.  *--- ClearRequestBlock ----------------------------------------
  239.  * Does what it says...
  240.  *--------------------------------------------------------------
  241.  */
  242.  
  243. void PQuery::ClearRequestBlock()
  244. {
  245.     itsPB->requestData  = NULL;
  246.     itsPB->requestSize  = 0L;
  247.     itsPB->requestStyle = 0;
  248.     itsPB->requestUnits = 0;
  249. }
  250.  
  251. // end of PQuery.cpp
  252.